package com.five.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 订单状态枚举
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {

    UNPAID(0, "待付款"),
    UNDELIVERED(1, "待发货"),
    UNRECEIVED(2, "待收货"),
    COMPLETED(3, "已完成"),
    CANCELED(4, "已取消"),
    REFUNDING(5, "退款中"),
    REFUNDED(6, "已退款");

    /**
     * 状态编码（对应数据库字段值）
     */
    private final Integer code;

    /**
     * 状态描述（用于前端展示）
     */
    private final String desc;

    /**
     * 根据编码获取枚举实例
     * @param code 状态编码
     * @return 对应的枚举实例，若未找到则返回null
     */
    public static OrderStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (OrderStatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }
}